home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / SHELL2.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  3KB  |  97 lines

  1. ;*********************************;
  2. ; WASM Command Shell              ;
  3. ; By Eric Tauck                   ;
  4. ;                                 ;
  5. ; Defines:                        ;
  6. ;                                 ;
  7. ;   RunSys  run command processor ;
  8. ;                                 ;
  9. ; Requires:                       ;
  10. ;                                 ;
  11. ;   ENVIRO.ASM                    ;
  12. ;   SHELL1.ASM                    ;
  13. ;   STACK.ASM                     ;
  14. ;   STRINGF.ASM                   ;
  15. ;*********************************;
  16.  
  17.         jmps    _shell2_end
  18.  
  19. ;--- data
  20.  
  21. _SHELL_MAXPTH   EQU     70                      ;maximum bytes for pathname
  22. _shell_cstr     DB      'COMSPEC='              ;COMSPEC string
  23. _shell_clen     EQU     $ - OFFSET _shell_cstr  ;length of COMSPEC
  24. _shell_carg     DB      0                       ;COMMAND.COM arguments
  25.  
  26. ;========================================
  27. ; Execute (another) copy of the command
  28. ; processor COMMAND.COM (or as named by
  29. ; the COMSPEC environment variable).
  30. ;
  31. ; Out: CY= set if error (AX= 0 if
  32. ;      COMSPEC not found, else DOS error
  33. ;      code).
  34.  
  35. RunSys  PROC    NEAR
  36.         push    di
  37.         push    si
  38.  
  39.         call    EnvRes          ;reset environment pointer
  40.  
  41. ;--- find location of COMMAND.COM using COMSPEC in the environment
  42.  
  43. _rnsys1 call    EnvGet                  ;get next string
  44.         jc      _rnsys5                 ;jump if none
  45.         mov     di, OFFSET _shell_cstr  ;command string
  46.         mov     cx, _shell_clen         ;length
  47.         push    ds
  48.         mov     ds, dx                  ;
  49.         mov     si, ax                  ;environment string at DS:SI
  50.         cld
  51.         rep
  52.         cmpsb                           ;compare strings
  53.         jne     _rnsys3                 ;jump if no match
  54.  
  55. ;--- found COMSPEC, skip preceding delimiters (probably shouldn't be any)
  56.  
  57. _rnsys2 cmp     BYTE [si], 32           ;check if delimiter
  58.         ja      _rnsys4                 ;jump if not
  59.         inc     si                      ;skip it
  60.         jmps    _rnsys2
  61.  
  62. ;--- COMSPEC not found, try next environment string
  63.  
  64. _rnsys3 pop     ds
  65.         jmps    _rnsys1
  66.  
  67. ;--- found COMSPEC and skipped delimiters, run program
  68.  
  69. _rnsys4 pop     ds
  70.         StkAll  di, _SHELL_MAXPTH       ;max bytes for COMMAND.COM pathname
  71.         mov     ax, si                  ;source in DX:AX
  72.         mov     cx, ds
  73.         mov     bx, di                  ;destination in CX:BX
  74.         call    StrCpyF                 ;copy string to local storage
  75.         mov     ax, di                  ;COMMAND.COM address
  76.         mov     bx, OFFSET _shell_carg  ;arguments
  77.         call    RunPro                  ;execute
  78.         mov     dx, ax                  ;save return code
  79.         lahf                            ;save flags
  80.         StkRel  _SHELL_MAXPTH           ;restore stack
  81.         pop     si
  82.         pop     di
  83.         sahf                            ;restore flags
  84.         mov     ax, dx                  ;restore return code
  85.         ret
  86.  
  87. ;--- error, could not find COMSPEC in environment
  88.  
  89. _rnsys5 sub     ax, ax          ;no error number
  90.         pop     si
  91.         pop     di
  92.         stc                     ;set carry for error
  93.         ret
  94.         ENDP
  95.  
  96. _shell2_end
  97.